package com.jxb.netty.network.netty.byteBuf;

import io.netty.buffer.*;
import io.netty.channel.PreferHeapByteBufAllocator;

/**
 * 类注释
 *
 * @author jiaobo
 * @date Created in 2024/8/26 23:01
 **/
public class Test {

    public static void main(String[] args) {
        //基于堆或者直接内存的buffer
        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();
        //基于堆内存存储的buffer
        ByteBuf byteBuf = ByteBufAllocator.DEFAULT.heapBuffer();
        //基于直接内存存储的buffer
        ByteBuf directBuffer = ByteBufAllocator.DEFAULT.directBuffer();
        //基于堆或者直接内存存储的缓冲区
        CompositeByteBuf byteBufs = ByteBufAllocator.DEFAULT.compositeBuffer();
        //基于套接字的io操作的buffer，具有 sun.misc.Unsafe 支持时，返回基于直接内存存储的 ByteBuf，否则返回的是堆内存
        ByteBuf ioBuffer = ByteBufAllocator.DEFAULT.ioBuffer();
        ByteBuf ioBuffer1 = PreferHeapByteBufAllocator.DEFAULT.ioBuffer();//返回的是堆内存的buffer

        //池化了ByteBuf实列
        ByteBuf buffer1 = PooledByteBufAllocator.DEFAULT.buffer();

        //Unpooled缓冲区
        //返回一个未池化基于堆内存的buffer
        ByteBuf buffer2 = Unpooled.buffer();
        //返回一个未池化基于直接内存的buffer
        ByteBuf byteBuf1 = Unpooled.directBuffer();
        //返回了一个包装给定数据的buffer
        Unpooled.wrappedBuffer(new byte[1024]);
        //返回了一个复制了给定数据的buffer
        Unpooled.copiedBuffer(new byte[1024]);

        //Byte的索引操作
        ByteBuf buf = Unpooled.buffer();
        //顺序访问
        System.out.println(byteBuf1.hasArray());

        //丢弃已经读过的字节
        ByteBuf buf1 = buf.discardReadBytes();
    }

}
